// api/ai_role_api/ai_role_update_user.go
package ai_role_api

import (
	"github.com/gin-gonic/gin"
	"muziai-server/global"
	"muziai-server/models"
	"muziai-server/utils/ref"
	"muziai-server/utils/res"
)

type AiRoleUpdateAdminRequest struct {
	RoleID   uint    `json:"roleID" binding:"required"`
	Title    *string `json:"title" mps:"title"`
	Avatar   *string `json:"avatar" mps:"avatar"`
	Category *string `json:"category" mps:"category"` // 角色分类
	Abstract *string `json:"abstract" mps:"abstract"`
	Prompt   *string `json:"prompt" mps:"prompt"`      // 提示词
	IsSquare *bool   `json:"isSquare" mps:"is_square"` // 是否在角色广场
	IsSystem *bool   `json:"isSystem" mps:"is_system"` // 是否是系统角色
	IsReview *bool   `json:"isReview" mps:"is_review"` // 是否在审核
}

func (AiRoleApi) AiRoleUpdateAdminView(c *gin.Context) {
	var cr AiRoleUpdateAdminRequest
	err := c.ShouldBindJSON(&cr)
	if err != nil {
		res.FailWithError(c, err)
		return
	}
	var model models.AiRoleModel
	err = global.DB.
		Take(&model, cr.RoleID).Error
	if err != nil {
		res.FailWithMsg(c, "角色不存在")
		return
	}

	maps, _ := ref.StructToMapByMaps(cr)
	delete(maps, "roleID")
	err = global.DB.Model(&model).Updates(maps).Error

	if err != nil {
		res.FailWithError(c, err)
		return
	}
	res.OkWithMsg(c, "角色更新成功")
	return
}
